//
//  NetMoniter.m
//  FunnyTime
//
//  Created by lanou on 15/10/6.
//  Copyright © 2015年 FunnyTimeTeem. All rights reserved.
//

#import "NetMoniter.h"

@implementation NetMoniter
static NetMoniter *_sharedClient = nil;
+ (instancetype)sharedClient {
    
    static dispatch_once_t onceToken;
    
    NSString * APIBaseURLString = [NSString stringWithFormat:@"https://api.app.net/"];
    ;
    
    dispatch_once(&onceToken, ^{
        _sharedClient = [[NetMoniter alloc] initWithBaseURL:[NSURL URLWithString:APIBaseURLString]];
        [_sharedClient setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]];
        
        
    });
    
    return _sharedClient;
}
- (void)dismissAlertViewNoLine:(UIAlertView *)alertView {
    [alertView dismissWithClickedButtonIndex:0 animated:NO];
}
- (void)setMonter {
    [_sharedClient.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN: {
//                //(@"网络已连接流量+++++");
                self.isCennected = YES;
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"当前使用的是流量" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
//                [self performSelector:@selector(dismissAlertViewNoLine:) withObject:alertView afterDelay:2];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:
//                //(@"网络已连接WIFI++++");
                self.isCennected = YES;
                
                break;
            case AFNetworkReachabilityStatusNotReachable: {
                //(@"当前网络不可用,请联系管理员++++");
                self.isCennected = NO;
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"当前网络不可用" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [self performSelector:@selector(dismissAlertViewNoLine:) withObject:alertView afterDelay:2];
                
                [alertView show];
                break;
            }
                
            default:
                break;
        }
    }];
    [_sharedClient.reachabilityManager startMonitoring];

}
@end
